package ch.bfh.abcm.rems.display;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;

import ch.bfh.abcm.rems.controller.MulticastController;
import ch.bfh.abcm.rems.display.subpanels.history.HistoryPanel;
import ch.bfh.abcm.rems.display.subpanels.periodic.PeriodicUpdatePanel;
import ch.bfh.abcm.rems.display.subpanels.state.StatePanel;

public class Mainframe extends JFrame{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    private static final int WIDTH = 1200;
    private static final int HEIGHT = 400;
    private static final Dimension mainframeSize = new Dimension(WIDTH, HEIGHT);
    private static final String TITLE = "REMS Display";
    
    private HistoryPanel historyPanel;
    private StatePanel statePanel;
    private PeriodicUpdatePanel periodicUpdatePanel;
    
    public Mainframe(MulticastController multicastController){
        
        this.setSize(mainframeSize);
        this.setTitle(TITLE);
        this.setResizable(true);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        
        this.setLayout(new BorderLayout());
        
        this.historyPanel = new HistoryPanel(WIDTH/2, HEIGHT);
        this.periodicUpdatePanel = new PeriodicUpdatePanel(WIDTH/2-50, HEIGHT/2-50);
        this.statePanel = new StatePanel(WIDTH/2-50, HEIGHT/2);
        
        multicastController.addObserver(historyPanel);
        multicastController.addObserver(statePanel);
        multicastController.addObserver(periodicUpdatePanel);
        
        this.add(historyPanel, BorderLayout.EAST);

        this.add(new LayoutHelper2(new LayoutHelper(periodicUpdatePanel, statePanel)), BorderLayout.WEST);
        
        this.setVisible(true);
    }

    private class LayoutHelper extends JPanel{
        
        /**
         * 
         */
        private static final long serialVersionUID = 1L;

        private LayoutHelper(JPanel one, JPanel two){
            this.setLayout(new BorderLayout());
            this.add(one, BorderLayout.NORTH);
            this.add(two, BorderLayout.SOUTH);
        }
    }
    private class LayoutHelper2 extends JPanel{
        
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        
        private LayoutHelper2(JPanel one){
            this.setLayout(new BorderLayout());
            this.add(one, BorderLayout.NORTH);
        }
    }
}
